package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.DoctorPriceBean;

import java.util.List;

/**
 * Created by Administrator on 2017/4/10.
 */

public class PopPayAdapter extends BaseAdapter {
    private Context context;
//    private String[] data;
    private int mSelect = -1;
    private List<DoctorPriceBean> data;
    public PopPayAdapter(Context context, List<DoctorPriceBean> data) {
        this.context = context;
        this.data = data;
    }
    public void changeSelected(int posion){
        if (posion!=mSelect){
            mSelect = posion;
            notifyDataSetChanged();
        }
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolders viewHolders = null;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.gridview_pay_item,null);
            viewHolders = new ViewHolders();
            viewHolders.tv_num = (TextView) convertView.findViewById(R.id.gridview_pay_item_tv);
            convertView.setTag(viewHolders);
        }else {
            viewHolders = (ViewHolders) convertView.getTag();
        }

        int count = data.get(position).getCount();
        if (data.get(position).getPrice()>0){
            int price = (int)data.get(position).getPrice();
            viewHolders.tv_num.setText(price+"元/"+count+"次");
        }else {
            double price = data.get(position).getPrice();
            viewHolders.tv_num.setText(price+"元/"+count+"次");
        }
        Log.i("------tvnum-->","text:"+viewHolders.tv_num.getText().toString());
        String isReferral = data.get(position).getIsReferral();

        if (!"0".equals(isReferral)){
                if (mSelect == position){
                    viewHolders.tv_num.setBackgroundResource(R.drawable.icon_grid_pay_recommend);
                    viewHolders.tv_num.setTextColor(context.getResources().getColor(R.color.white));
                }else {
                    viewHolders.tv_num.setBackgroundResource(R.drawable.icon_grid_pay_recommend_back);
                    viewHolders.tv_num.setTextColor(context.getResources().getColor(R.color.black_text));
                }
        }else {
          //  mSelect==position
            if (mSelect==position){
                viewHolders.tv_num.setTextColor(context.getResources().getColor(R.color.white));
                viewHolders.tv_num.setBackgroundResource(R.drawable.gridview_item_textback_green);
            }else {
                viewHolders.tv_num.setTextColor(context.getResources().getColor(R.color.black_text));
                viewHolders.tv_num.setBackgroundResource(R.drawable.gridview_item_textbackgroud);
            }
        }


        return convertView;
    }
    static class ViewHolders{
        TextView tv_num;
    }

}
